﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class WebControl_Client_BookTicket_1 : System.Web.UI.UserControl
{
    ListAndProcessData ws = new ListAndProcessData();
    private int status = 0;
    private string check = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        string starlocation = Request.QueryString["starlocation"];
        string endlocation = Request.QueryString["endlocation"];
        string dateplan = Request.QueryString["dateplan"];
        if(!IsPostBack){          
            var a = ws.getbusname();
            foreach (var item in a)
            {
                DropDownList1.Items.Add(item.Busname);
            }
        }
        ListView1.DataSource = ws.getBookPlan(starlocation, endlocation, dateplan);
        ListView1.DataBind();        
    }
    protected void btnsearch_Click(object sender, EventArgs e)
    {
        if (DropDownList2.SelectedValue == "NotAvailable")
        {
            status = 1;
        }
        else if (DropDownList2.SelectedValue == "Available")
        {
            status = 0;
        }
        else
        {
            status = 2;
        }
        var checkerror = ws.searchBusName(DropDownList1.SelectedValue, status);
        if (checkerror.Count == 0)
        {
            lblcheck.Visible = true;
        }
        else
        {
            lblcheck.Visible = false;
            ListView1.DataSource = ws.searchBusName(DropDownList1.SelectedValue, status);
        }
        ListView1.DataBind();
    }
    protected void Refresh_Click1(object sender, EventArgs e)
    {
        lblcheck.Visible = false;
        string starlocation = Request.QueryString["starlocation"];
        string endlocation = Request.QueryString["endlocation"];
        string dateplan = Request.QueryString["dateplan"];
        ListView1.DataSource = ws.getBookPlan(starlocation, endlocation, dateplan);
        ListView1.DataBind();  
    }
}